//
//  YCArticleCollectionViewCell.m
//  YCSchool
//
//  Created by Yanglixia on 16/5/15.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//

#import "YCArticleCollectionViewCell.h"
#import "YCMutablePhotoItemView.h"
#import "YCPraiseView.h"
#import "YCCommentView.h"
#import "YCCommentsTableViewCell.h"
#import "YCPlayMusicView.h"
#import "YCPraiseModel.h"
#import "YCDespiseModel.h"
#import "YCCommentModel.h"
#import "YCSessionRightViewButton.h"

@interface YCArticleCollectionViewCell()<UITableViewDataSource,UITableViewDelegate,YCCommentsTableViewCellDelegate>
@property (nonatomic,strong) UIView *mainView;//主
//@property (nonatomic,strong) UIView *leftView;//左边
@property (nonatomic,strong) UIImageView *headImgView;//头像
@property (nonatomic,strong) YCSessionRightViewButton *sendDailyNoteButton;//发日志
@property (nonatomic,strong) UIButton *button;//点击头像
@property (nonatomic,strong) UIView *rightView;//右边
@property (nonatomic,strong) UILabel *dayLabel;//日
@property (nonatomic,strong) UILabel *monthLabel;//月
@property (nonatomic,strong) UILabel *contentLabel;//内容
@property (nonatomic,strong) UIButton *moreButton;//查看更多
@property (nonatomic,strong) UIView *photoView;//图片
@property (nonatomic,strong) UILabel *timeLabel;//时间
@property (nonatomic,strong) UIButton *cancelButton;//删除
@property (nonatomic,strong) UIButton *reportButton;//举报
@property (nonatomic,strong) UIButton *commentsButton;//评论按钮
@property (nonatomic,strong) UIView *praiseView;//赞
@property (nonatomic,strong) UIImageView *icon1ImgView;//赞小图
@property (nonatomic,strong) UILabel *praiseAttributedLabel;//赞文本
@property (nonatomic,strong) UIView *pityView;//怜
@property (nonatomic,strong) UIImageView *icon2ImgView;//怜小图
@property (nonatomic,strong) UILabel *despiseAttributedLabel;//怜文本
@property (nonatomic,strong) UIImageView *lineImgView;//分隔线
@property (nonatomic,assign) BOOL updatedConstraints;
@property (nonatomic,strong) UITableView *tableView;//评论回复

@property (nonatomic,strong) YCArticlelistModel *model;//模型
@end

@implementation YCArticleCollectionViewCell
@synthesize leftView = _leftView;

+ (BOOL)requiresConstraintBasedLayout
{
    return YES;
}

///2
- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self makeSubview];
    }
    return self;
}

///3
- (void)makeSubview
{
    _mainView = [[UIView alloc] init];
    _mainView.userInteractionEnabled = YES;
    [self.contentView addSubview:_mainView];
    
    _leftView = [[UIView alloc] init];
    _leftView.hidden = YES;
    [self.mainView addSubview:_leftView];
    
    _rightView = [[UIView alloc] init];
    _rightView.userInteractionEnabled = YES;
    [self.mainView addSubview:_rightView];
    
    _headImgView = [[UIImageView alloc]init];
    _headImgView.contentMode = UIViewContentModeScaleAspectFill;
    _headImgView.clipsToBounds = YES;
    _headImgView.layer.cornerRadius = 50/2;
    [_headImgView yc_setWebImageWithURLString:@"" holderSize:CGSizeMake(50, 50)];
    [self.leftView addSubview:_headImgView];
    
    _button = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button addTarget:self action:@selector(buttonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [self.leftView addSubview:_button];
    
    YCSessionRightViewButton *sendNoteButton = [[YCSessionRightViewButton alloc] init];
    [sendNoteButton setImage:[UIImage imageNamed:@"发日志"] forState:UIControlStateNormal];
    [sendNoteButton setTitle:@"发日志" forState:UIControlStateNormal];
    sendNoteButton.imageView.contentMode = UIViewContentModeCenter;
    _sendDailyNoteButton = sendNoteButton;
    [self.leftView addSubview:_sendDailyNoteButton];
    
    _dayLabel = [[UILabel alloc]init];
    _dayLabel.font = [UIFont boldSystemFontOfSize:28];
    _dayLabel.text = @"15";
    _dayLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
    [self.rightView addSubview:_dayLabel];
    
    _monthLabel = [[UILabel alloc]init];
    _monthLabel.font = [UIFont boldSystemFontOfSize:12];
    _monthLabel.text = @"4月";
    _monthLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
    [self.rightView addSubview:_monthLabel];
    
    _contentLabel = [[UILabel alloc]init];
    _contentLabel.font = [UIFont systemFontOfSize:15];
    _contentLabel.numberOfLines = 10;//默认最多10行,可点击查看更多
    _contentLabel.textAlignment = NSTextAlignmentJustified;
    _contentLabel.userInteractionEnabled = YES;
    [self.rightView addSubview:_contentLabel];
    
    UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
    longPressGr.minimumPressDuration = 1.0;
    [self.contentLabel addGestureRecognizer:longPressGr];
    
    _moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_moreButton setTitle:@"查看全文" forState:UIControlStateNormal];
    [_moreButton setTitleColor:[UIColor yc_colorWithUInt:0x00b4ff] forState:UIControlStateNormal];
    [_moreButton addTarget:self action:@selector(moreButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    _moreButton.hidden = YES;
    _moreButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.rightView addSubview:_moreButton];
    
    _photoView = [[UIView alloc]init];
    _photoView.userInteractionEnabled = YES;
    _photoView.backgroundColor = [UIColor whiteColor];
    [self.rightView addSubview:_photoView];
    
    _timeLabel = [[UILabel alloc]init];
    _timeLabel.text = @"今天 18:32";
    _timeLabel.textColor = [UIColor yc_colorWithUInt:0x808080];
    _timeLabel.font = [UIFont systemFontOfSize:11];
    [self.rightView addSubview:_timeLabel];
    
    // 删除
    _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelButton setTitle:@"删除" forState:UIControlStateNormal];
    _cancelButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [_cancelButton setTitleColor:[UIColor yc_colorWithUInt:0x5270a7] forState:UIControlStateNormal];
    [_cancelButton addTarget:self action:@selector(cancelButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [self.rightView addSubview:_cancelButton];
    
    // 举报
    _reportButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_reportButton setTitle:@"举报" forState:UIControlStateNormal];
    _reportButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [_reportButton setTitleColor:[UIColor yc_colorWithUInt:0x5270a7] forState:UIControlStateNormal];
    [_reportButton addTarget:self action:@selector(reportButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [self.rightView addSubview:_reportButton];
    
    _commentsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_commentsButton addTarget:self action:@selector(commentsButtonEventTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [_commentsButton setImage:[UIImage imageNamed:@"so_comments"] forState:UIControlStateNormal];
    [self.rightView addSubview:_commentsButton];
    
    ///
    {
        _praiseView = [[UIView alloc]init];
        _praiseView.backgroundColor = [UIColor yc_colorWithUInt:0xf3f3f5];
        [self.rightView addSubview:_praiseView];
        
        _icon1ImgView = [[UIImageView alloc]init];
        _icon1ImgView.image = [UIImage imageNamed:@"so_praise"];
        [self.praiseView addSubview:_icon1ImgView];
        
        _praiseAttributedLabel = [[UILabel alloc] init];
        _praiseAttributedLabel.textColor = [UIColor yc_colorWithUInt:0xeb8894];
        _praiseAttributedLabel.font = [UIFont systemFontOfSize:12];
        _praiseAttributedLabel.numberOfLines = 0;
        _praiseAttributedLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _praiseAttributedLabel.text = @"";
        [self.praiseView addSubview:_praiseAttributedLabel];
        
        _pityView = [[UIView alloc]init];
        _pityView.backgroundColor = [UIColor yc_colorWithUInt:0xf3f3f5];
        [self.rightView addSubview:_pityView];
        
        _icon2ImgView = [[UIImageView alloc]init];
        _icon2ImgView.image = [UIImage imageNamed:@"so_despise"];
        [self.pityView addSubview:_icon2ImgView];
        
        _despiseAttributedLabel = [[UILabel alloc] init];
        _despiseAttributedLabel.textColor = [UIColor yc_colorWithUInt:0xbf8bbf];
        _despiseAttributedLabel.font = [UIFont systemFontOfSize:12];
        _despiseAttributedLabel.numberOfLines = 0;
        _despiseAttributedLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _despiseAttributedLabel.text = @"";
        [self.pityView addSubview:_despiseAttributedLabel];
    }
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.scrollEnabled = NO;
    [self.rightView addSubview:_tableView];
    
    _lineImgView = [[UIImageView alloc]init];
    _lineImgView.backgroundColor = [UIColor yc_colorWithUInt:0xe6e6e6];
    [self.mainView addSubview:self.lineImgView];
}

///5
- (void)updateConstraints
{
    if(!self.updatedConstraints)
    {
        _updatedConstraints = YES;
        
//                CGFloat width = 247.0 / 320 * kScreenWidth;
        
        [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.left.right.equalTo(self.contentView);
        }];
        
        [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.width.equalTo(@75);
            make.top.equalTo(@2);
            make.bottom.equalTo(@0);
        }];
        
        [self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.leftView.mas_right);
            make.right.equalTo(@0);
            make.top.equalTo(@2);
            make.bottom.equalTo(@0);
        }];
        
        [self.headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@10);
            make.width.height.equalTo(@50);
            make.centerX.equalTo(self.leftView);
        }];
        
        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@10);
            make.width.height.equalTo(@50);
            make.centerX.equalTo(self.leftView);
        }];
        
        [self.sendDailyNoteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headImgView.mas_bottom).offset(20);
            make.centerX.equalTo(self.leftView);
            make.width.height.equalTo(@50);
        }];
        
        [self.dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@10);
            make.right.equalTo(@(-10));
        }];
        [self.monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.dayLabel.mas_bottom);
            make.right.equalTo(@(-10));
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.monthLabel.mas_bottom).offset(10);
            make.left.equalTo(@0);
            make.width.equalTo(@(kScreenWidth-85));
        }];
        
        [self.moreButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentLabel.mas_bottom);
            make.width.equalTo(@55);
            make.height.equalTo(@(20));
            make.right.equalTo(@(-10));
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.photoView.mas_bottom).offset(10);
            make.left.equalTo(self.contentLabel);
        }];
        
        [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.timeLabel);
            make.left.equalTo(self.timeLabel.mas_right).offset(20);
            make.height.equalTo(@14);
        }];
        
        [self.reportButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.timeLabel);
            make.left.equalTo(self.cancelButton.mas_right).offset(30);
            make.height.equalTo(@14);
        }];
        [self.commentsButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.timeLabel);
            make.right.equalTo(@(-10));
            make.height.equalTo(@30);
        }];
        
        [self.lineImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.rightView);
            make.right.bottom.equalTo(self.mainView);
            make.height.equalTo(@1);
        }];
    }
    
    if (0 == _model.praise.count)
    {
        self.icon1ImgView.hidden = YES;
        
        [self.praiseView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.equalTo(self.rightView);
            make.right.equalTo(@(-10));
            make.height.equalTo(@0);
        }];
    }
    else
    {
        self.icon1ImgView.hidden = NO;
        
        [self.icon1ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@3);
            make.left.equalTo(@5);
            make.width.height.equalTo(@12);
        }];
        
        [self.praiseAttributedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.icon1ImgView.mas_right).offset(5);
            make.top.equalTo(self.icon1ImgView.mas_top);
            make.right.lessThanOrEqualTo(@(-10));
        }];
        
        [self.praiseView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.equalTo(self.rightView);
            make.right.equalTo(@(-10));
            make.bottom.equalTo(self.praiseAttributedLabel.mas_bottom).offset(5);
        }];
    }
    
    if (0 == _model.despise.count)
    {
        self.icon2ImgView.hidden = YES;
        
        [self.pityView mas_remakeConstraints:^(MASConstraintMaker *make) {
            [make removeExisting];
            make.top.equalTo(self.praiseView.mas_bottom);
            make.left.equalTo(self.rightView);
            make.right.equalTo(@(-10));
            make.height.equalTo(@0);
        }];
    }
    else
    {
        self.icon2ImgView.hidden = NO;
        
        [self.icon2ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@3);
            make.left.equalTo(@5);
            make.width.height.equalTo(@12);
        }];
        
        [self.despiseAttributedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.icon2ImgView.mas_right).offset(5);
            make.top.equalTo(self.icon2ImgView.mas_top);
            make.right.lessThanOrEqualTo(@(-10));
        }];
        
        [self.pityView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.praiseView.mas_bottom);
            make.left.equalTo(self.rightView);
            make.right.equalTo(@(-10));
            make.bottom.equalTo(self.despiseAttributedLabel.mas_bottom).offset(5);
        }];
    }
    
    [self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(15);
        make.left.equalTo(self.rightView);
        make.height.equalTo(@(_model.talentHeight));
        make.right.equalTo(@(-10));
    }];
    
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rightView);
        make.right.equalTo(@(-10));
        make.top.equalTo(self.pityView.mas_bottom);
        make.bottom.equalTo(self.rightView.mas_bottom).offset(-20);
    }];
    
    [super updateConstraints];
}

///1
+ (CGFloat)heightForArticle:(YCArticlelistModel *)model
{
    if (!model)
    {
        return 0;
    }
    
    CGFloat width = kScreenWidth - 75 - 15;
    
    __block CGFloat lineSpace = 3;
    [YCAdapter performOtherBlock:^{
        lineSpace = 3;
    } IPhone6Block:^{
        lineSpace = 6;
    } IPhone6pBlock:^{
        lineSpace = 8;
    }];
    
    CGFloat contentHeight = model.l_contentHeight;
    
    if (contentHeight > ([UIFont systemFontOfSize:15].lineHeight+lineSpace)*10)
    {
        if (model.l_isLookAll != YES)
        {
            contentHeight = ([UIFont systemFontOfSize:15].lineHeight+lineSpace)*10;
        }
    }
    
    CGFloat height = 5;
    height += [UIFont systemFontOfSize:28].lineHeight;//日
    height += [UIFont systemFontOfSize:12].lineHeight;//月
    height += 10;
    height += contentHeight;//文本
    height += 15;
    height += model.talentHeight;//照片
    height += 10;
    height += 10;
    height += 14;//[UIFont systemFontOfSize:11].lineHeight;
    height += 10;
    
#pragma mark - praise
    
    if (0 != model.praise.count)
    {
        NSMutableArray *praiseArray = [[NSMutableArray alloc]init];
        
        for (YCPraiseModel *praiseModel in model.praise)
        {
            [praiseArray addObject:praiseModel.uname];
        }
        
        NSString *praiseStr = [praiseArray componentsJoinedByString:@","];
        
        NSMutableAttributedString *praise = [[NSMutableAttributedString alloc] initWithString:praiseStr attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
        
        CGFloat praiseHeight = [praise boundingRectWithSize:CGSizeMake(width-30, CGFLOAT_MAX)
                                                    options:NSStringDrawingUsesLineFragmentOrigin
                                                    context:nil].size.height;
        height += praiseHeight;
        height += 15;
    }
    
#pragma mark - pity
    
    if (0 != model.despise.count)
    {
        NSMutableArray *pityArray = [[NSMutableArray alloc]init];
        
        for (YCDespiseModel *pityModel in model.despise)
        {
            [pityArray addObject:pityModel.uname];
        }
        
        NSString *pityStr = [pityArray componentsJoinedByString:@","];
        
        NSMutableAttributedString *pity = [[NSMutableAttributedString alloc] initWithString:pityStr attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
        
        CGFloat pityHeight = [pity boundingRectWithSize:CGSizeMake(width-30, CGFLOAT_MAX)
                                                options:NSStringDrawingUsesLineFragmentOrigin
                                                context:nil].size.height;
        height += pityHeight;
        height += 15;
    }
    
    for (YCCommentModel *commentModel in model.comment)
    {
        height += commentModel.l_rowHeight;
    }
    
    height += 20;
    
    return height;
}

///4
- (void)relodWithArticle:(YCArticlelistModel *)model
{
    _model = model;
    
    [self.tableView reloadData];
    
    __block CGFloat lineSpace = 3;
    [YCAdapter performOtherBlock:^{
        lineSpace = 3;
    } IPhone6Block:^{
        lineSpace = 6;
    } IPhone6pBlock:^{
        lineSpace = 8;
    }];
    
//    [self.headImgView yc_setWebImageWithURLString:model.headPhoto holderSize:CGSizeMake(50, 50)];

    [self.headImgView yc_setWebImageWithURLString:model.photoArray.firstObject holderSize:CGSizeMake(50, 50)];
    self.dayLabel.text = [NSString stringWithFormat:@"%zd",[NSDate yc_getDayIntegerFromDateString:model.addtime_str formatter:@"yyyy-MM-dd HH:mm:ss"]];
    self.monthLabel.text = [NSString stringWithFormat:@"%zd月",[NSDate yc_getMonthIntegerFromDateString:model.addtime_str formatter:@"yyyy-MM-dd HH:mm:ss"]];
    self.timeLabel.text = [model yc_dateProcessWithAddTime:model.addtime_str];
    
    NSString *contentString = model.content;
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpace];
    //    paragraphStyle.lineBreakMode =  NSLineBreakByWordWrapping;
    
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc] initWithString:contentString attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    
    self.contentLabel.attributedText = content;
    
    if (model.l_contentHeight > ([UIFont systemFontOfSize:15].lineHeight+lineSpace)*10)
    {
        self.moreButton.hidden = NO;
        
        if (model.l_isLookAll == YES)
        {
            self.contentLabel.numberOfLines = 0;
            self.moreButton.hidden = YES;
        }
        else
        {
            self.contentLabel.numberOfLines = 10;
        }
    }
    else
    {
        self.moreButton.hidden = YES;
    }
    
    [self.photoView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    
    for (NSString *url in model.photoArray)
    {
        [array addObject:url];
    }
    
    YCMutablePhotoItemView *view = [[YCMutablePhotoItemView alloc]initWithArray:array];
    [self.photoView addSubview:view];
    
    NSMutableArray *praiseArray = [[NSMutableArray alloc]init];
    
    for (YCPraiseModel *praiseModel in model.praise)
    {
        [praiseArray addObject:praiseModel.uname];
    }
    
    self.praiseAttributedLabel.text = [praiseArray componentsJoinedByString:@","];
    
    NSMutableArray *pityArray = [[NSMutableArray alloc]init];
    
    for (YCPraiseModel *pityModel in model.despise)
    {
        [pityArray addObject:pityModel.uname];
    }
    
    self.despiseAttributedLabel.text = [pityArray componentsJoinedByString:@","];
    
//    if (model.voiceUrl.length > 0)
//    {
//        self.playMusicView.hidden = NO;
//        
//        if ([model.voiceUrl rangeOfString:@".wav"].location != NSNotFound || [model.voiceUrl rangeOfString:@".amr"].location != NSNotFound)
//        {
//            NSString *urlString = model.voiceUrl;
//            self.playMusicView.stringPath = urlString;
//        }
//        else
//        {
//            NSString *urlString = model.voiceUrl;
//            self.playMusicView.stringPath = [urlString  go_urlEncodeString];
//        }
//    }
//    else
//    {
//        self.playMusicView.hidden = YES;
//    }
}

// 点击了评论三角
- (void)commentsButtonEventTouchUpInside:(UIButton *)sender
{
    if([self.delegate respondsToSelector:@selector(didArticleWithModel:cell:touchUpInsideViewWithBUtton:)])
    {
        [self.delegate didArticleWithModel:_model cell:self touchUpInsideViewWithBUtton:sender];
    }
}

// 点击了头像
- (void)buttonTouchUpInside:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(didHeadIconButtonTouchUpInside:)])
    {
        [self.delegate didHeadIconButtonTouchUpInside:_model];
    }
}

///查看更多
- (void)moreButtonTouchUpInside:(UIButton *)sender
{
    YCLog(@"点击了查看更多");
    if (_model.l_isLookAll == YES)
    {
        _model.l_isLookAll = NO;
    }
    else
    {
        _model.l_isLookAll = YES;
    }
    
    if([self.delegate respondsToSelector:@selector(needToReloadTalentCollectionView:)])
    {
        [self.delegate needToReloadArticleCollectionView:self];
    }
}

// 删除
- (void)cancelButtonTouchUpInside:(UIButton *)sender
{
    YCLog(@"点击了删除");
}

// 举报
- (void)reportButtonTouchUpInside:(UIButton *)sender
{
    YCLog(@"点击了举报");
    if([self.delegate respondsToSelector:@selector(didReportButtonTouchUpInside:)])
    {
        [self.delegate didReportButtonTouchUpInside:_model];
    }
}

- (void)needToReloadTabelView
{
    [self.tableView reloadData];
}

-(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        if([self.delegate respondsToSelector:@selector(didLongPressWithModel:)])
        {
            [self.delegate didLongPressWithModel:_model];
        }
    }
}

#pragma mark -tableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _model.comment.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCCommentModel*commentsModel = _model.comment[indexPath.row];
    
    return commentsModel.l_rowHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCCommentModel *commentModel = _model.comment[indexPath.row];
    
    YCCommentsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commentsTableViewCell"];
    if (!cell)
    {
        cell = [[YCCommentsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commentsTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor yc_colorWithUInt:0xf3f3f5];
    }
    
    [cell relodCommentsWithModel:commentModel];
    cell.delegate = self;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    YCCommentModel *model = _model.comment[indexPath.row];
    
//    if ([[GOLoginUser loginUser].userId isEqualToString:model.fromUserId])
//    {
//        @go_weakify(self);
//        
//        GOActionSheet *sheet = [[GOActionSheet alloc] initWithTitle:nil message:nil cancelButtonTitle:@"取消" otherButtonTitles:@"删除",nil];
//        [sheet showInView:self mask:YES click:^(NSUInteger index, GOActionSheet *sheet) {
//            
//            if (index == 1)
//            {
//                [[GOWebService service]postAction:GOAPCommentInfoDelete params:@{@"commentInfoId":model.commentInfoId} success:^(AFHTTPRequestOperation *operation, GOWebServiceResponse *response) {
//                    
//                    if (response.success)
//                    {
//                        @go_strongify(self);
//                        if(!self) return;
//                        
//                        [SVProgressHUD showSuccessWithStatus:@"删除成功"];
//                        [_model.commentList removeObject:model];
//                        
//                        dispatch_async(dispatch_get_main_queue(), ^{
//                            
//                            if([self.delegate respondsToSelector:@selector(needToReloadTalentCollectionView:)])
//                            {
//                                [self.delegate needToReloadTalentCollectionView:self];
//                            }
//                        });
//                    }
//                    
//                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//                    
//                }];
//            }
//            
//        } cancel:^(NSUInteger index, GOActionSheet *sheet)
//         {
//             
//         }];
//    }
//    else
//    {
//        GOCommentView *commentView = [[GOCommentView alloc]init];
//        NSMutableDictionary *params = [@{} mutableCopy];
//        
//        if ([model.fromUserId isEqualToString:[GOLoginUser loginUser].userId])
//        {
//            commentView.titleLab.text = @"评论";
//        }
//        else
//        {
//            commentView.titleLab.text = [NSString stringWithFormat:@"回复%@",model.fromUserNickname];
//            params[@"parentId"] = model.commentInfoId;
//        }
//        
//        [commentView showWithSendBlock:^(NSString *text) {
//            
//            [SVProgressHUD showWithStatus:@"正在提交"];
//            
//            params[@"infoId"] = _model.articleInfoId;
//            params[@"commentContent"] = text;
//            
//            @go_weakify(self);
//            
//            [[GOWebService service]postAction:GOAPICommentInfoAdd params:params success:^(AFHTTPRequestOperation *operation, GOWebServiceResponse *response) {
//                
//                if (response.success)
//                {
//                    [SVProgressHUD showSuccessWithStatus:@"评论成功"];
//                    
//                    NSError *error;
//                    GOCommentsModel *commentsModel = [[GOCommentsModel alloc]init];
//                    commentsModel = [MTLJSONAdapter modelOfClass:[GOCommentsModel class] fromJSONDictionary:response.data error:&error];
//                    commentsModel.fromUserNickname = [GOLoginUser loginUser].userNickName;
//                    commentsModel.fromUserHeadPhoto = [GOLoginUser loginUser].userHeadPhoto;
//                    
//                    if ([model.fromUserId isEqualToString:[GOLoginUser loginUser].userId])
//                    {
//                        commentsModel.toUserNickname = [GOLoginUser loginUser].userNickName;
//                        commentsModel.toUserHeadPhoto = [GOLoginUser loginUser].userHeadPhoto;
//                    }
//                    else
//                    {
//                        commentsModel.toUserNickname = model.fromUserNickname;
//                        commentsModel.toUserHeadPhoto = model.fromUserHeadPhoto;
//                    }
//                    
//                    if(!error)
//                    {
//                        @go_strongify(self);
//                        if(!self) return;
//                        
//                        [_model.commentList addObject:commentsModel];
//                        
//                        dispatch_async(dispatch_get_main_queue(), ^{
//                            
//                            if([self.delegate respondsToSelector:@selector(needToReloadTalentCollectionView:)])
//                            {
//                                [self.delegate needToReloadTalentCollectionView:self];
//                            }
//                        });
//                    }
//                }
//                
//            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//                
//            }];
//            
//        } cancel:^{
//            
//        }];
//    }
}

#pragma mark - YCCommentsTableViewCell delegate

- (void)didTouchUpInsideWithUserName:(YCArticlelistModel *)model
{
    if ([self.delegate respondsToSelector:@selector(didReportButtonTouchUpInside:)])
    {
        [self.delegate didReportButtonTouchUpInside:self.model];
    }
}



@end
